package com.itheima.springbootwebtlias.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.springbootwebtlias.controller.StudentController;
import com.itheima.springbootwebtlias.mapper.StudentMapper;
import com.itheima.springbootwebtlias.pojo.Emp;
import com.itheima.springbootwebtlias.pojo.PageResult;
import com.itheima.springbootwebtlias.pojo.Student;
import com.itheima.springbootwebtlias.pojo.StudentQueryParam;
import com.itheima.springbootwebtlias.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;


    //学员分页查询
    @Override
    public PageResult page(StudentQueryParam queryParam) {
        //1.使用分页插件来实现分页查询
        //1.1 启动分页插件                   页码                  条数
        PageHelper.startPage(queryParam.getPage(),queryParam.getPageSize());

        //1.2 调用被分页插件增强的持久层方法
        Page<Student> page = studentMapper.selectByCondition(queryParam);

        //1.3 从分页插件增强方法的返回结果中，获取数据封装到PageResult返回
        PageResult pageResult = new PageResult(page.getTotal(), page.getResult());
        return pageResult;
    }

    //添加学员
    @Override
    public void add(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.add(student);
    }

    //根据id查询学员
    @Override
    public Student selectById(Integer id) {
        Student student = studentMapper.selectById(id);
        return student;
    }

    //修改班级信息
    @Override
    public void modifyStudent(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.modifyStudent(student);
    }

    //删除学员
    @Override
    public void deleteBatch(List<Integer> ids) {
        studentMapper.deleteBatch(ids);
    }

    //学生违纪处理
    @Override
    public void violate(Integer id, Short score) {
        studentMapper.violate(id,score);
    }



}
